package com.trendata.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.trendata.dao.IImageDao;
import com.trendata.domain.Image;

@Service("imageService")
public class ImageService {

	@Autowired
	private IImageDao imageDao;

	public void insert(Image image) {
		imageDao.insert(image);
	}

	public int deleteById(long id) {
		return imageDao.deleteById(id);
	}

	public int deleteByOpenId(String openId) {
		return imageDao.deleteByOpenId(openId);
	}

	public void update(Image image) {
		imageDao.update(image);
	}

	public Image selectById(long id) {
		return imageDao.selectById(id);
	}

	public Image selectByUrl(String url) {
		Image image = imageDao.selectByUrl(url);
		return image;
	}

	/**
	 * 根据参数查询
	 * 
	 * @param userOpenId
	 * @param shopOpenId
	 * @param state
	 * @param startIndex
	 * @param size
	 * @return
	 */
	public List<Image> selectByParamters(String userOpenId, Long shopOpenId, Integer state, int startIndex, int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userOpenId", userOpenId);
		map.put("shopOpenId", shopOpenId);
		map.put("state", state);
		map.put("startIndex", startIndex);
		map.put("size", size);
		return imageDao.selectByParams(map);
	}

	/**
	 * 查询数量
	 * 
	 * @param userOpenId
	 * @param shopOpenId
	 * @param state
	 * @return
	 */
	public int selectCountByParams(String userOpenId, Long shopOpenId, Integer state) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userOpenId", userOpenId);
		map.put("shopOpenId", shopOpenId);
		map.put("state", state);
		return imageDao.selectCountByParams(map);
	}

}
